<?php
class Keywordships extends UaModel {
	var $name = "Keywordship";
	var $media_name, $media_dir;
	var $search_sql;
	var $search_keyword;
	
	function Keywordships() {
		$class_name = $this->name;
		$this->Keywordship = & new $class_name ( );
	}
	
	function getShip($keyword_id) {
		$this->primaryKey = "ke";
		$tmp_res = $this->read ( "ka,kb,kc", $keyword_id );
		return $tmp_res;
	}
	
	function setMediaName($media_name) {
		$this->media_name = $media_name;
	}
	
	function getMediaName() {
		return $this->media_name;
	}
	
	function setMediaDir($media_dir) {
		$this->media_dir = $media_dir;
	}
	
	function getMediaDir() {
		return $this->media_dir;
	}
	
	function setSearchKeyword($keyword) {
		$this->search_keyword = $keyword;
	}
	
	function getSearchKeyword() {
		return $this->search_keyword;
	}
	
	function setSearchSql($searchkeyword_type) {
		global $trade, $company, $product;
		switch ($searchkeyword_type) {
			case 1 :
				$table = $trade->getTable ();
				$subtitle = "topic";
				$p_id = "ki";
				$this->setMediaName ( "trades/" );
				$this->setMediaDir ( "buy" );
				$content = "content";
				break;
			case 2 :
				$table = $trade->getTable ();
				$p_id = "ka";
				$subtitle = "topic";
				$this->setMediaName ( "trades/" );
				$this->setMediaDir ( "sell" );
				$content = "content";
				break;
			case 3 :
				$table = $company->getTable ();
				$p_id = "kb";
				$subtitle = "name";
				$this->setMediaName ( "company/" );
				$this->setMediaDir ( "company" );
				$content = "description";
				break;
			case 4 :
				$p_id = "kc";
				$table = $product->getTable ();
				$subtitle = "name";
				$this->setMediaName ( "products/" );
				$this->setMediaDir ( "product" );
				$content = "content";
				break;
			default :
				$p_id = "kc";
				$table = $product->getTable ();
				$subtitle = "name";
				$this->setMediaName ( "products/" );
				$this->setMediaDir ( "product" );
				$content = "content";
				break;
		}
		$searching_keyword = $this->getSearchKeyword ();
		$sql = "select ks.kf as ItemPrior,a.id as ItemId,a." . $subtitle . " as ItemSubject,a.keywords as ItemWords,a.created as ItemCreateDate,a." . $content . " as ItemContent,a.picture as ItemPicture from " . $table . " a left join eos_keywordships ks on a.id = ks." . $p_id . " left join eos_keywords k on ks.ke=k.id where instr(keywords,'$searching_keyword') order by ks.kf desc,a.id desc";
		$this->search_sql = $sql;
	}
	
	function getSearchSql() {
		return $this->search_sql;
	}
}
?>